package com.wn.project.web;

import com.wn.common.ResponseEntity;
import com.wn.entity.Project;
import com.wn.project.service.ProjectService;
import com.wn.utils.OssManagerUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

/**
 * @program: pms
 * @ClassName ProjectController
 * @description:项目controller
 * @author: LRW
 * @create: 2022-10-19 15:26
 * @Version 1.0
 **/
@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @PostMapping("/add")
    public ResponseEntity add(@RequestBody Project project){
        return ResponseEntity.success;
    }

    /***
     * @description: 文件上传
     * @param: file
     * @return: com.wn.common.ResponseEntity 文件路径
     * @author Lrw
     * @date: 2022/10/19 15:27
     */
    @RequestMapping("/upload")
    public ResponseEntity upload(MultipartFile file) {
        String url = null;
        try {
            String filename = file.getOriginalFilename();
            filename= UUID.randomUUID().toString().replace("-","")+"."+filename;
            url = OssManagerUtil.uploadImage(filename,file.getInputStream().available(),file.getInputStream());
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseEntity("400","fail","文件上传失败");
        }

        return new ResponseEntity(url);
    }
}
